//
//  Target.swift
//  TCSTARNewWork
//
//  Created by kate on 2023/5/15.
//

import Foundation
import Moya

public enum NetWorkAPI {
    
    //发送消息
    case sendMsg(sendId: String, receiveId: String, typeId: String, content: String)
    
    //接收消息
    case receiveMsg(receiveId: String, msgParamList: [[String:String]])
}


extension NetWorkAPI: TargetType{
        
    public var baseURL: URL {
        
        return URL(string: "http://112.124.23.27/")!
    }
    
    public var path: String {
        switch self{
        case .sendMsg:
            return "/msg/sendMsg"
        case .receiveMsg:
            return "msg/getMsg"
        }
    }
    
    public var method: Moya.Method {
        switch self{
        case .sendMsg:
            return .post
        case .receiveMsg:
            return .post
        }
    }
    
    public var sampleData: Data {
        
        return "{}".data(using: String.Encoding.utf8)!
    }
    
    public var task: Moya.Task {
        var param: [String: Any] = [:]
        switch self {
        case .sendMsg(let sendId, let receiveId, let typeId, let content):
            param["sendId"] = sendId
            param["receiveId"] = receiveId
            param["typeId"] = typeId
            param["content"] = content
            return .requestParameters(parameters: param, encoding: JSONEncoding.default)
        case .receiveMsg(let receiveId, let msgParamList):
            param["receiveId"] = receiveId
            param["msgParamList"] = msgParamList
            return .requestParameters(parameters: param, encoding: JSONEncoding.default)
        }
    }
    
    public var headers: [String : String]? {
        return ["content-type": "application/json;charset=utf-8;"]
    }
    
}
